/**
 * 数据库连接
 */
 const mysql = require("mysql")

 const pool = mysql.createPool({
     connectionLimit:    10,
     host:               "localhost",
     user:               "root",
     password:           "root",
     database:           "uclass"
 })
 
 function Query(sql, args) {
     return new Promise( (resolve, reject) => {
         pool.getConnection( (err, connection)=> {
             connection.query(sql, args, (err, result)=> {
                 if(err){
                     console.log("执行sql出现错误", err)
                     reject(err)
                 } else {
                     resolve(result)
                 }
                 connection.release()
             })
         })
     })
 }
 
 module.exports = Query
 